import Player.Player;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.Image; //image ;P
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.*;


public class GamePanel extends JPanel implements ActionListener, KeyListener {

    //************************' SOURCES *****************************************
    // (1) code for KeyListener: http://www.youtube.com/watch?v=p9Y-NBg8eto
    // (2) code taken from http://www.java2s.com/Code/Java/Swing-JFC/Panelwithbackgroundimage.htm
    //***************************************************************************


   boolean isMenu = false;
   boolean buttons = true;

   Image backgroundImage;

   Menu menu = new Menu();

   Player mPlayer = new Player();

    public GamePanel() {
        this.addKeyListener(this); //source - (1)
        setFocusable(true); //fokuserar på detta "objektet" så man kan använda keylistener typ... //source - (1)
        setFocusTraversalKeysEnabled(false); //tar bort focus för typ TAB, shift och sånt //source - (1)
        //------------------------------------------------------------------
    }


    /**
     *  /Paintcomponent är det som målas upp i panelen!
     * GRAFIK HÄR GRAFIK HÄR GRAFIK HÄR GRAFIK HÄR GRAFIK HÄR GRAFIK HÄR GRAFIK HÄR
     * GRAFIK HÄR GRAFIK HÄR GRAFIK HÄR GRAFIK HÄR GRAFIK HÄR GRAFIK HÄR GRAFIK HÄR
     *
     * */

    public void gameArea(){
        mPlayer.moveShip();
        mPlayer.startShooting();
    }

    public void paintComponent ( Graphics g ) {
        super.paintComponent( g );

        if(isMenu) {
            menu.drawTheMenu(g);
            menu.menuBackground(g);
        }

        else {
            drawBackground(g);
            //rita ut game
            mPlayer.Draw(g);
            gameArea();
        }

        repaint(); //Gör att paintComponent körs igen!!!
    } // end of paintComponent

    public void drawBackground(Graphics g){
        int backgroundX = 0;
        int backgroundY = 0;
        backgroundImage = new ImageIcon("images/space.gif").getImage();
        g.drawImage(backgroundImage, backgroundX, backgroundY, 800, 600, this);
    }


    //Det som händer vid actions
    public void actionPerformed(ActionEvent e) {

    }




    public void keyTyped(KeyEvent e) {

    }


    public void keyReleased(KeyEvent e) {
        mPlayer.stopShip(e.getKeyCode());
        mPlayer.stopShooting(e.getKeyCode());
    }

    public void keyPressed(KeyEvent e) {
        mPlayer.checkButtons(e.getKeyCode());
    }

}